﻿using System;

namespace PerformanceTests
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] buffer = new byte[1 * 1024 * 1024];
            Random rdm = new Random();
            rdm.NextBytes(buffer);
            string s1 = String.Empty, s2 = String.Empty, s3 = String.Empty;


            for (int i = 0; i < 6; i++)
            {
                Benchmark b1 = new Benchmark("Base64 Time");
                s1 = Convert.ToBase64String(buffer, 0, buffer.Length);
                b1.Dispose();
                TimeSpan ts1 = b1.Elapsed;

                Benchmark b2 = new Benchmark("Base85P5 Compressed Time");
                s2 = Base85P5.Base85P5.EncodeAndCompress(buffer);
                b2.Dispose();
                TimeSpan ts2 = b2.Elapsed;

                Benchmark b3 = new Benchmark("Base85P5 Not Compressed Time");
                s3 = Base85P5.Base85P5.Encode(buffer);
                b3.Dispose();
                TimeSpan ts3 = b3.Elapsed;
                

                long timesSlower = ts2.Ticks / ts1.Ticks;
                Console.WriteLine($"Base85P5 Compressed slower than Base64 {timesSlower}");
                timesSlower = ts3.Ticks / ts1.Ticks;
                Console.WriteLine($"Base85P5 Not Compressed slower than Base64 {timesSlower}");
                Console.WriteLine();
            }


            Console.WriteLine("======================================================================");
            double perc1 = s1.Length * 100.0 / buffer.Length;
            double perc2 = s2.Length * 100.0 / buffer.Length;
            double perc3 = s3.Length * 100.0 / buffer.Length;
            Console.WriteLine($"Base64 Length {s1.Length}, increased by {perc1}%");
            Console.WriteLine($"Base85P5 Compressed Length {s2.Length}, increased by {perc2}%");
            Console.WriteLine($"Base85P5 Not Compressed Length {s3.Length}, increased by {perc3}%");
            Console.WriteLine();


            Console.ReadKey();
        }
    }
}
